<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/9/18
 * Time: 15:38
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Manage extends Base {
    public function index(){
        if (request()->isAjax()) {
            extract(input());
            $map =array();
            if(isset($keyword)&&$keyword!="")
            {
                $map['uuu.user_real_name'] = ['like',"%" . $keyword . "%"];
            }

            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 50;
            $map['a.order_status'] = array('>',7);
            $count = Db::name('order')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.order_jms_user','left')
                ->group('a.order_jms_user,a.order_fb_ym')
                  ->where($map)
                ->count();// 获取总条数
            $lists = Db::name('order')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.order_jms_user','left')
                ->group('a.order_jms_user,a.order_fb_ym')
                ->where($map)
                ->page($NowPage, $limits)
                ->field('a.*,uuu.user_username')
                ->select();
            foreach ($lists as $key=>&$vo){
                $where['order_jms_user'] = $vo['order_jms_user'];
                $where['order_fb_ym'] = $vo['order_fb_ym'];
                $order_freight = Db::table('up_order')->where($where)->sum('order_freight');
                $price3 = 0;
                //平台抽成
                if($order_freight<30000){
                    $price3 = $order_freight*0.0358;
                }elseif ($order_freight>=30000&&$order_freight){
                    $price3 = $order_freight*0.0258;
                }elseif ($order_freight>=300000){
                    $price3 = $order_freight*0.0198;
                }
                $vo['price'] = round($price3,2);
                $vo['freight'] = $order_freight;
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count,'data' => $lists]);
        }
        return $this->fetch();
    }
}